package com.bjsxt;

import com.bjsxt.service.AccountService;
import io.seata.core.context.RootContext;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableDiscoveryClient
@MapperScan("com.bjsxt.mapper")
@RestController
public class AccountServiceApplication {

    @Autowired
    private AccountService accountService ;

    public static void main(String[] args) {
        SpringApplication.run(AccountServiceApplication.class ,args) ;
    }

    @GetMapping("/debit/{userId}/{money}")
    public ResponseEntity<Void> debit(
            @PathVariable("userId") String userId ,
            @PathVariable("money") Integer money
    ){
        String xid = RootContext.getXID();
        System.out.println("全局的事务id:"+xid);
        accountService.debit(userId ,money);
        return ResponseEntity.ok().build() ;
    }
}
